from rest_framework import serializers

from goods.models import SPU, Brand, GoodsCategory


class BrandSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = ("id","name")
# [
#     {
#         "id": 1,
#         "name": "Apple"
#     },


class SPUSerializer(serializers.ModelSerializer):
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    brand_id = serializers.IntegerField()
    brand = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SPU
        fields = "__all__"
        extra_kwargs = {
            "sales":{"read_only": True},
            "comments":{"read_only": True},
            "category1":{"read_only": True},
            "category2": {"read_only": True},
            "category3": {"read_only": True},
        }
  #  "counts": "商品SPU总数量",
  #       "lists": [
  #           {
  #               "id": "商品SPU ID",
  #               "name": "SPU名称",
  #               "brand": "品牌名称",
  #               "brand_id": "品牌id",
  #               "category1_id": "一级分类id",
  #               "category2_id": "二级分类id",
  #               "category3_id": "三级分类id",
  #               "sales": "SPU商品销量",
  #               "comments": "SPU商品评论量",
  #               "desc_detail": "商品详情",
  #               "desc_pack": "商品包装",
  #               "desc_service": "售后服务"
  #           },
  #           ...
  #      ],
  #      "page": "页码",
  #      "pages": "总页数",
  #      "pagesize": "页容量"
  # }




class GoodCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = ("id","name")
 # [
 #        {
 #            "id": "一级分类id",
 #            "name": "一级分类名称"
 #        },
 #        ...
 #    ]